﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:LOAN_RETURN
	/// </summary>
	public partial class LOAN_RETURN : BaseDAL<GSLMS.Entity.TB_LOAN_RETURN>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public LOAN_RETURN()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_LOAN_RETURN model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_CONNO", model.CONNO),
								new OracleParameter("P_LOANNO", model.LOANNO),
								new OracleParameter("P_APPLYNO", model.APPLYNO),
								new OracleParameter("P_INTTYPE", model.INTTYPE),
								new OracleParameter("P_TRANAMT", model.TRANAMT),
								new OracleParameter("P_DISAMT", model.DISAMT),
								new OracleParameter("P_PAYMODE", model.PAYMODE),
								new OracleParameter("P_EXCHANGENO", model.EXCHANGENO),
								new OracleParameter("P_PAYDATE", model.PAYDATE),
								new OracleParameter("P_SHOULDPHASE", model.SHOULDPHASE),
								new OracleParameter("P_SHOULDCAPITAL", model.SHOULDCAPITAL),
								new OracleParameter("P_SHOULDINT", model.SHOULDINT),
								new OracleParameter("P_SHOULDCOST", model.SHOULDCOST),
								new OracleParameter("P_SHOULDFEES", model.SHOULDFEES),
								new OracleParameter("P_SHOULDDELAYINT", model.SHOULDDELAYINT),
								new OracleParameter("P_SHOULDDELAYAMT", model.SHOULDDELAYAMT),
								new OracleParameter("P_TOTALSHOULD", model.TOTALSHOULD),
								new OracleParameter("P_REDCAPITAL", model.REDCAPITAL),
								new OracleParameter("P_REDINT", model.REDINT),
								new OracleParameter("P_REDCOST", model.REDCOST),
								new OracleParameter("P_REDFEES", model.REDFEES),
								new OracleParameter("P_REDDELAYINT", model.REDDELAYINT),
								new OracleParameter("P_REDDELAYAMT", model.REDDELAYAMT),
								new OracleParameter("P_TOTALRED", model.TOTALRED),
								new OracleParameter("P_ACTCAPITAL", model.ACTCAPITAL),
								new OracleParameter("P_ACTINT", model.ACTINT),
								new OracleParameter("P_ACTCOST", model.ACTCOST),
								new OracleParameter("P_ACTFEES", model.ACTFEES),
								new OracleParameter("P_ACTDELAYINT", model.ACTDELAYINT),
								new OracleParameter("P_ACTDELAYAMT", model.ACTDELAYAMT),
								new OracleParameter("P_TOTALACT", model.TOTALACT),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_CREATEBY", model.CREATEBY),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_CONFRIMBY", model.CONFRIMBY),
								new OracleParameter("P_CONFIRMDATE", model.CONFIRMDATE),
								new OracleParameter("P_ACTIONBY", model.ACTIONBY),
								new OracleParameter("P_ACTIONDATE", model.ACTIONDATE),
								new OracleParameter("P_ACCOUNTID", model.ACCOUNTID),
								new OracleParameter("P_ACCOUNTNAME", model.ACCOUNTNAME),
								new OracleParameter("P_REMARK", model.REMARK)};
  
			for (int i = 0; i < 47; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_return_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_LOAN_RETURN model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_CONNO", model.CONNO),
								new OracleParameter("P_LOANNO", model.LOANNO),
								new OracleParameter("P_APPLYNO", model.APPLYNO),
								new OracleParameter("P_INTTYPE", model.INTTYPE),
								new OracleParameter("P_TRANAMT", model.TRANAMT),
								new OracleParameter("P_DISAMT", model.DISAMT),
								new OracleParameter("P_PAYMODE", model.PAYMODE),
								new OracleParameter("P_EXCHANGENO", model.EXCHANGENO),
								new OracleParameter("P_PAYDATE", model.PAYDATE),
								new OracleParameter("P_SHOULDPHASE", model.SHOULDPHASE),
								new OracleParameter("P_SHOULDCAPITAL", model.SHOULDCAPITAL),
								new OracleParameter("P_SHOULDINT", model.SHOULDINT),
								new OracleParameter("P_SHOULDCOST", model.SHOULDCOST),
								new OracleParameter("P_SHOULDFEES", model.SHOULDFEES),
								new OracleParameter("P_SHOULDDELAYINT", model.SHOULDDELAYINT),
								new OracleParameter("P_SHOULDDELAYAMT", model.SHOULDDELAYAMT),
								new OracleParameter("P_TOTALSHOULD", model.TOTALSHOULD),
								new OracleParameter("P_REDCAPITAL", model.REDCAPITAL),
								new OracleParameter("P_REDINT", model.REDINT),
								new OracleParameter("P_REDCOST", model.REDCOST),
								new OracleParameter("P_REDFEES", model.REDFEES),
								new OracleParameter("P_REDDELAYINT", model.REDDELAYINT),
								new OracleParameter("P_REDDELAYAMT", model.REDDELAYAMT),
								new OracleParameter("P_TOTALRED", model.TOTALRED),
								new OracleParameter("P_ACTCAPITAL", model.ACTCAPITAL),
								new OracleParameter("P_ACTINT", model.ACTINT),
								new OracleParameter("P_ACTCOST", model.ACTCOST),
								new OracleParameter("P_ACTFEES", model.ACTFEES),
								new OracleParameter("P_ACTDELAYINT", model.ACTDELAYINT),
								new OracleParameter("P_ACTDELAYAMT", model.ACTDELAYAMT),
								new OracleParameter("P_TOTALACT", model.TOTALACT),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_CREATEBY", model.CREATEBY),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_CONFRIMBY", model.CONFRIMBY),
								new OracleParameter("P_CONFIRMDATE", model.CONFIRMDATE),
								new OracleParameter("P_ACTIONBY", model.ACTIONBY),
								new OracleParameter("P_ACTIONDATE", model.ACTIONDATE),
								new OracleParameter("P_ACCOUNTID", model.ACCOUNTID),
								new OracleParameter("P_ACCOUNTNAME", model.ACCOUNTNAME),
								new OracleParameter("P_REMARK", model.REMARK)};
  
			for (int i = 0; i < 47; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_return_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_loan_return_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_LOAN_RETURN DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_LOAN_RETURN model = new GSLMS.Entity.TB_LOAN_RETURN();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["CONID"]!=null && dr["CONID"].ToString()!="")
				{
					model.CONID=OracleHelper.ToLong(dr["CONID"].ToString());
				}
				if(dr["LOANID"]!=null && dr["LOANID"].ToString()!="")
				{
					model.LOANID=OracleHelper.ToLong(dr["LOANID"].ToString());
				}
				if(dr["CUSTNAME"]!=null && dr["CUSTNAME"].ToString()!="")
				{
					model.CUSTNAME=dr["CUSTNAME"].ToString();
				}
				if(dr["CUSTNO"]!=null && dr["CUSTNO"].ToString()!="")
				{
					model.CUSTNO=dr["CUSTNO"].ToString();
				}
				if(dr["CONNO"]!=null && dr["CONNO"].ToString()!="")
				{
					model.CONNO=dr["CONNO"].ToString();
				}
				if(dr["LOANNO"]!=null && dr["LOANNO"].ToString()!="")
				{
					model.LOANNO=dr["LOANNO"].ToString();
				}
				if(dr["APPLYNO"]!=null && dr["APPLYNO"].ToString()!="")
				{
					model.APPLYNO=dr["APPLYNO"].ToString();
				}
				if(dr["INTTYPE"]!=null && dr["INTTYPE"].ToString()!="")
				{
                    model.INTTYPE = OracleHelper.ToInt(dr["INTTYPE"].ToString());
				}
				if(dr["TRANAMT"]!=null && dr["TRANAMT"].ToString()!="")
				{
					model.TRANAMT=OracleHelper.ToDecimal(dr["TRANAMT"].ToString());
				}
				if(dr["DISAMT"]!=null && dr["DISAMT"].ToString()!="")
				{
					model.DISAMT=OracleHelper.ToDecimal(dr["DISAMT"].ToString());
				}
				if(dr["PAYMODE"]!=null && dr["PAYMODE"].ToString()!="")
				{
                    model.PAYMODE = OracleHelper.ToInt(dr["PAYMODE"].ToString());
				}
				if(dr["EXCHANGENO"]!=null && dr["EXCHANGENO"].ToString()!="")
				{
					model.EXCHANGENO=dr["EXCHANGENO"].ToString();
				}
				if(dr["PAYDATE"]!=null && dr["PAYDATE"].ToString()!="")
				{
					model.PAYDATE=DateTime.Parse(dr["PAYDATE"].ToString());
				}
				if(dr["SHOULDPHASE"]!=null && dr["SHOULDPHASE"].ToString()!="")
				{
					model.SHOULDPHASE=dr["SHOULDPHASE"].ToString();
				}
				if(dr["SHOULDCAPITAL"]!=null && dr["SHOULDCAPITAL"].ToString()!="")
				{
					model.SHOULDCAPITAL=OracleHelper.ToDecimal(dr["SHOULDCAPITAL"].ToString());
				}
				if(dr["SHOULDINT"]!=null && dr["SHOULDINT"].ToString()!="")
				{
					model.SHOULDINT=OracleHelper.ToDecimal(dr["SHOULDINT"].ToString());
				}
				if(dr["SHOULDCOST"]!=null && dr["SHOULDCOST"].ToString()!="")
				{
					model.SHOULDCOST=OracleHelper.ToDecimal(dr["SHOULDCOST"].ToString());
				}
				if(dr["SHOULDFEES"]!=null && dr["SHOULDFEES"].ToString()!="")
				{
					model.SHOULDFEES=OracleHelper.ToDecimal(dr["SHOULDFEES"].ToString());
				}
				if(dr["SHOULDDELAYINT"]!=null && dr["SHOULDDELAYINT"].ToString()!="")
				{
					model.SHOULDDELAYINT=OracleHelper.ToDecimal(dr["SHOULDDELAYINT"].ToString());
				}
				if(dr["SHOULDDELAYAMT"]!=null && dr["SHOULDDELAYAMT"].ToString()!="")
				{
					model.SHOULDDELAYAMT=OracleHelper.ToDecimal(dr["SHOULDDELAYAMT"].ToString());
				}
				if(dr["TOTALSHOULD"]!=null && dr["TOTALSHOULD"].ToString()!="")
				{
					model.TOTALSHOULD=OracleHelper.ToDecimal(dr["TOTALSHOULD"].ToString());
				}
				if(dr["REDCAPITAL"]!=null && dr["REDCAPITAL"].ToString()!="")
				{
					model.REDCAPITAL=OracleHelper.ToDecimal(dr["REDCAPITAL"].ToString());
				}
				if(dr["REDINT"]!=null && dr["REDINT"].ToString()!="")
				{
					model.REDINT=OracleHelper.ToDecimal(dr["REDINT"].ToString());
				}
				if(dr["REDCOST"]!=null && dr["REDCOST"].ToString()!="")
				{
					model.REDCOST=OracleHelper.ToDecimal(dr["REDCOST"].ToString());
				}
				if(dr["REDFEES"]!=null && dr["REDFEES"].ToString()!="")
				{
					model.REDFEES=OracleHelper.ToDecimal(dr["REDFEES"].ToString());
				}
				if(dr["REDDELAYINT"]!=null && dr["REDDELAYINT"].ToString()!="")
				{
					model.REDDELAYINT=OracleHelper.ToDecimal(dr["REDDELAYINT"].ToString());
				}
				if(dr["REDDELAYAMT"]!=null && dr["REDDELAYAMT"].ToString()!="")
				{
					model.REDDELAYAMT=OracleHelper.ToDecimal(dr["REDDELAYAMT"].ToString());
				}
				if(dr["TOTALRED"]!=null && dr["TOTALRED"].ToString()!="")
				{
					model.TOTALRED=OracleHelper.ToDecimal(dr["TOTALRED"].ToString());
				}
				if(dr["ACTCAPITAL"]!=null && dr["ACTCAPITAL"].ToString()!="")
				{
					model.ACTCAPITAL=OracleHelper.ToDecimal(dr["ACTCAPITAL"].ToString());
				}
				if(dr["ACTINT"]!=null && dr["ACTINT"].ToString()!="")
				{
					model.ACTINT=OracleHelper.ToDecimal(dr["ACTINT"].ToString());
				}
				if(dr["ACTCOST"]!=null && dr["ACTCOST"].ToString()!="")
				{
					model.ACTCOST=OracleHelper.ToDecimal(dr["ACTCOST"].ToString());
				}
				if(dr["ACTFEES"]!=null && dr["ACTFEES"].ToString()!="")
				{
					model.ACTFEES=OracleHelper.ToDecimal(dr["ACTFEES"].ToString());
				}
				if(dr["ACTDELAYINT"]!=null && dr["ACTDELAYINT"].ToString()!="")
				{
					model.ACTDELAYINT=OracleHelper.ToDecimal(dr["ACTDELAYINT"].ToString());
				}
				if(dr["ACTDELAYAMT"]!=null && dr["ACTDELAYAMT"].ToString()!="")
				{
					model.ACTDELAYAMT=OracleHelper.ToDecimal(dr["ACTDELAYAMT"].ToString());
				}
				if(dr["TOTALACT"]!=null && dr["TOTALACT"].ToString()!="")
				{
					model.TOTALACT=OracleHelper.ToDecimal(dr["TOTALACT"].ToString());
				}
				if(dr["STATUS"]!=null && dr["STATUS"].ToString()!="")
				{
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
				}
				if(dr["CREATEBY"]!=null && dr["CREATEBY"].ToString()!="")
				{
					model.CREATEBY=dr["CREATEBY"].ToString();
				}
				if(dr["CREATEDATE"]!=null && dr["CREATEDATE"].ToString()!="")
				{
					model.CREATEDATE=DateTime.Parse(dr["CREATEDATE"].ToString());
				}
				if(dr["CONFRIMBY"]!=null && dr["CONFRIMBY"].ToString()!="")
				{
					model.CONFRIMBY=dr["CONFRIMBY"].ToString();
				}
				if(dr["CONFIRMDATE"]!=null && dr["CONFIRMDATE"].ToString()!="")
				{
					model.CONFIRMDATE=DateTime.Parse(dr["CONFIRMDATE"].ToString());
				}
				if(dr["ACTIONBY"]!=null && dr["ACTIONBY"].ToString()!="")
				{
					model.ACTIONBY=dr["ACTIONBY"].ToString();
				}
				if(dr["ACTIONDATE"]!=null && dr["ACTIONDATE"].ToString()!="")
				{
					model.ACTIONDATE=DateTime.Parse(dr["ACTIONDATE"].ToString());
				}
				if(dr["ACCOUNTID"]!=null && dr["ACCOUNTID"].ToString()!="")
				{
					model.ACCOUNTID=OracleHelper.ToLong(dr["ACCOUNTID"].ToString());
				}
				if(dr["ACCOUNTNAME"]!=null && dr["ACCOUNTNAME"].ToString()!="")
				{
					model.ACCOUNTNAME=dr["ACCOUNTNAME"].ToString();
				}
				if(dr["REMARK"]!=null && dr["REMARK"].ToString()!="")
				{
					model.REMARK=dr["REMARK"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_LOAN_RETURN GetByID(long ID)
		{
			GSLMS.Entity.TB_LOAN_RETURN sModel = new GSLMS.Entity.TB_LOAN_RETURN();
			string sql = "";
			sql = "select * from TB_LOAN_RETURN where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_LOAN_RETURN> GetList(GSLMS.Entity.TB_LOAN_RETURN searchParam)
		{
			var list=new List<GSLMS.Entity.TB_LOAN_RETURN>();
			DataTable dt = null;
			string tblName = "TB_LOAN_RETURN";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_LOAN_RETURN model = new GSLMS.Entity.TB_LOAN_RETURN();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

